package ipebg.mzk.provider.system.rest_service.impl;

import ipebg.mzk.facade.entity.MsAdminUser;
import ipebg.mzk.facade.system.rest_service.IRestUserService;
import ipebg.mzk.provider.system.dao.UserDao;

import java.util.List;

import javax.annotation.Resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;

@Path("demo")
@Service(protocol = "rest")
public class RestUserService implements IRestUserService{
	private static final Log log = LogFactory.getLog(RestUserService.class);
	
	@Resource(name = "userDao")
	private UserDao userDao;
	
	@Override
    @GET
    @Path("greeting")
	//@Consumes({ MediaType.APPLICATION_JSON })
	//@Produces({ MediaType.APPLICATION_JSON })
	@Consumes("application/json; charset=UTF-8")
	@Produces("application/json; charset=UTF-8")
	@Transactional(readOnly=true)
	@Cacheable(value="mzk.RestUserService.findUserByEmpNo", key = "'findUserByEmpNo.key_'+#empNo")
	public String findUserByEmpNo(@QueryParam("empNo") String empNo) {
		MsAdminUser user=null;
		String strResult="";
		try{
			List<MsAdminUser> userList = userDao.findByProperty(MsAdminUser.class,new String[]{"loginName"},new Object[]{empNo});
			if(userList.size() > 0){
				user=userList.get(0);
				strResult= JSON.toJSONString(user);
			}
		}catch(Exception e){
			log.error(e.getMessage());
		}
		log.info(strResult);
		return strResult;		
	}

}
